---
title: "Replication material for 'Why Do Citizens (Not) Support Democratic Innovations? The Role of Instrumental Motivations in Support for Participatory Budgeting'"

author: | 
        | Ramon van der Does
        | Jaroslaw Kantorowicz

date: |
      | January 18, 2021
      
output: html_notebook
---

# Installing/loading required packages

```{r}

#install.packages("cregg")
#install.packages("cjoint")
#install.packages("tidyverse")
#devtools::install_github("jaredhuling/jcolors")
#install.packages("ggpubr")
#install.packages("arm")
#install.packages("GGally")
#install.packages("grid")
#install.packages("xlsx")
#install.packages("quanteda")
#install.packages("topicmodels")

library(cregg)
library(cjoint)
library(tidyverse)
library(jcolors)
library(ggpubr)
library(arm)
library(GGally)
library(grid)

```

# Load data for study 2

```{r}

rat_distance_final <- read.csv(file="study_2.csv")

rat_distance_final$residents_allowed_submit <- as.factor(rat_distance_final$residents_allowed_submit)
rat_distance_final$projects_allowed <- as.factor(rat_distance_final$projects_allowed)
rat_distance_final$support_municipality <- as.factor(rat_distance_final$support_municipality)
rat_distance_final$choice_winning_project <- as.factor(rat_distance_final$choice_winning_project)
rat_distance_final$project_location <- as.factor(rat_distance_final$project_location)


```


# Assumption checks: the carry over effect and profile order effect

```{r}

cj_anova(rat_distance_final, selected ~ 
                             residents_allowed_submit +
                             projects_allowed +
                             support_municipality + 
                             choice_winning_project +
                             project_location, 
                             by = ~task, 
                             id = ~responseid)
        
cj_anova(rat_distance_final, selected ~ 
                             residents_allowed_submit +
                             projects_allowed +
                             support_municipality + 
                             choice_winning_project +
                             project_location, 
                             by = ~profile, 
                             id = ~responseid)

```

# AMCE regression

```{r}

rat_distance_final$project_location <- factor(rat_distance_final$project_location, 
                                              levels = c("On one's street",
                                                         "1 street away",
                                                         "4 streets away"))

rat_distance_final$support_municipality <- factor(rat_distance_final$support_municipality, 
                                                  levels= c("No extra support", 
                                                            "Organizing discussion", 
                                                            "Helping to develop the project"))

rat_amce_distance <- cj(rat_distance_final,
                      selected ~ 
                      residents_allowed_submit + 
                      projects_allowed + 
                      support_municipality + 
                      choice_winning_project + 
                      project_location, 
                      id = ~responseid, 
                      estimate = "amce",
                      feature_order = c("residents_allowed_submit",
                                        "projects_allowed",
                                        "support_municipality",
                                        "choice_winning_project",
                                        "project_location"),
                      feature_labels = c(residents_allowed_submit = "Who can submit a project?", 
                                         projects_allowed = "What projects are allowed?",
                                         project_location = "Where is the winning projected located?", 
                                         support_municipality = "Does the muninicipality offer any support?", 
                                         choice_winning_project="Who is choosing the winning project?"))


```

# Figure 3 Results study 2

```{r}

plot_rat_amce_distance <- plot(rat_amce_distance, 
                     vline=0.0, 
                     size=1, 
                     feature_headers = FALSE)

plot_rat_amce_final_distance <- plot_rat_amce_distance +
           theme(legend.position="none") + 
           theme(axis.text.y = element_text(colour = "black")) +
           theme(axis.text.x = element_text(colour = "black")) +
           theme(plot.title = element_text(hjust = 1.0, vjust = 3)) +
           theme(text = element_text(size=15))  +
           ggplot2::facet_wrap(~feature, ncol=1, scales = "free_y") +
           geom_text(subset(rat_amce_distance, estimate!=0), mapping=aes(label=round(estimate,3)), 
                     parse = TRUE, color="black", size=3, check_overlap = TRUE, 
                     vjust = 1.4) +scale_color_jcolors("pal11") +
          theme(panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(),
            strip.background = element_blank(),
            panel.border = element_rect(colour = "black"))
            

plot(plot_rat_amce_final_distance)

plot_rat_amce_final_distance %>% ggsave(filename = "figure_3.png",
                                width = 8, 
                                height = 8, 
                                dpi = 150, 
                                units = "in", 
                                device='png')

```

